﻿using System.Collections.Generic;
using HVACWebService.Cloud.Able;
using HVACWebService.Common;
using HVACWebService.DataAccese.DataService;
using HVACWebService.DataAccese.Entity;
using HVACWebService.DomainModel.Able;

namespace HVACWebService.Business
{
    public class ShareDeviceService
    {
        /// <summary>
        /// 分享码绑定设备
        /// </summary>
        /// <param name="shareOpenId"></param>
        /// <param name="shareCode"></param>
        /// <param name="sourceOpenId"></param>
        /// <param name="deviceId"></param>
        /// <param name="ableDeviceId"></param>
        public int ShareCodeBindDevice(string sourceOpenId, string deviceId, string ableDeviceId, string shareOpenId, string shareCode)
        {
            var ableDeviceCloudService = new AbleDeviceCloudService();
            var isShare = ableDeviceCloudService.ShareCodeBindDevice(shareOpenId, shareCode, deviceId);
            if (isShare)
            {
                return CreateShareDevice(sourceOpenId, deviceId, ableDeviceId, shareOpenId, shareCode);
            }
            return 0;

        }



        /// <summary>
        /// 获取ShareCode
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="physicalDeviceId"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public AbleShareCode GetShareCode(string deviceId, string physicalDeviceId, string openId)
        {
            var  ableDeviceCloudService = new AbleDeviceCloudService();
            return ableDeviceCloudService.GetShareCode(deviceId, physicalDeviceId, openId);
        }


        /// <summary>
        /// 添加用户绑定信息
        /// </summary>
        /// <param name="sourceOpenId"></param>
        /// <param name="deviceId"></param>
        /// <param name="ableDeviceId"></param>
        /// <param name="shareOpenId"></param>
        /// <param name="shareCode"></param>
        /// <returns></returns>
        public int CreateShareDevice(string sourceOpenId, string deviceId, string ableDeviceId, string shareOpenId, string shareCode)
        {
            var shareDeviceDataAccess = new ShareDeviceDataAccess();
            return shareDeviceDataAccess.CreateShareDevice(sourceOpenId, deviceId, ableDeviceId, shareOpenId, shareCode);
        }


        /// <summary>
        /// 获得设备分享信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public List<ShareDevice> GetShareDeviceByOpenIdAnd(string openId, string deviceId)
        {
            var shareDeviceDataAccess = new ShareDeviceDataAccess();
            return shareDeviceDataAccess.GetShareDeviceByOpenIdAnd(openId, deviceId);
        }
    }
}